package com.wen.big_event.contorller;

import com.wen.big_event.pojo.Result;
import com.wen.big_event.pojo.User;
import com.wen.big_event.service.UserService;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Validated
public class Usercontorller {

    @Autowired
    private UserService userService;
    //注册
    @PostMapping("/register")
    public Result register(@Pattern(regexp = "^\\S{5,16}$") String username,@Pattern(regexp = "^\\S{5,16}$") String password){
        //查询用户
      User u = userService.findByUserName(username);
      if(u==null){
          userService.register(username,password);
          return Result.success();
      }else {
          return Result.error("用户已被占用");
      }
    }
}
